/**
 * FH Technikum-Wien,
 *
 * Alcatraz - Remote - Projekt
 * Group B5
 *
 * @author Andreas Schmid
 * @author Roman Leonhartsberger
 * @author Bernhard Höchtl
 * @author Christian Pipp
 *
 * @date 2011/04/22
 * @version 1.0
 *
 **/

package alcatraz.server;

import alcatraz.common.PlayerData;
import alcatraz.common.IAlcatraz;
import alcatraz.common.AlcatrazException;

import java.util.ArrayList;

/**
 *
 * @author christian
 */
public class Game implements IAlcatraz {

    private ArrayList<PlayerData> playerList;

    public void addPlayer (PlayerData players) throws AlcatrazException {

        /* If Object has a null value throw Exception */
        if(players == null)  {
            throw new NullPointerException();
        }

        /* Check if the Maximum number of players is already reached */
        if(playerList.size() >= MAX_NUMBER_OF_PLAYERS)   {
            throw new AlcatrazException("Maximum number of players already reached...");
        }

        /* Check if the name is in List of the game */
        for(PlayerData temp : playerList) {
            if(temp.getNickName().equals(players.getNickName())) 
                throw new AlcatrazException("Name alread in use...");
            }

        /* Finally add Player to list */
        playerList.add(players);
    }

     public boolean removePlayer(PlayerData player) {
        return playerList.remove(player);
    }

     /**
     * gibt die Anzahl der Spieler im derzeitigen Game zurück
     * @return Anzahl der Spieler
     */
    public int getNumberOfPlayers() {
        return this.playerList.size();
    }

    /**
     * die kompllete Spieler Liste wird retourniert
     *
     * @return ArrayList of PlayerData
     */
    public ArrayList<PlayerData> getPlayers() {
        return this.playerList;
    }

    /**
     * Der Name des Spielers wird neu gesetzt
     *
     */
    public void setName(PlayerData player, String newNameOfPlayer)  {
        for(PlayerData temp : playerList) {
            if(temp.getNickName().equals(newNameOfPlayer))
                System.out.println("Set new name");
            }
    }

}
